
using ActionSystem.Core.HitLogic;
using System;
using UnityEngine;
using XMLib;
namespace ActionSystem.Core
{
    /// <summary>
    /// RangeConfig
    /// </summary>
    [Serializable]
    public class RangeConfig
    {
        [Drawable(false)]
        [SlotTag]
        public int slotID = 0;
        [Drawable(false)]
        [BoxTag]
        public int boxTypeID = 0;

        [BoxData.BoxDataTypes]
        [SerializeReference]
        public BoxData.IBoxData data;
        public Type GetDataType() => data?.GetType() ?? null;

        [Ranges.RangeTypes]
        [SerializeReference]//可以使Value设置为根据继承该类型的子类
        public Ranges.IItem value;
         
        public Type GetValueType() => value?.GetType() ?? null;

        public RangeConfig()
        {
        }

        public RangeConfig(RangeConfig config)
        {
            this.slotID = config.slotID;
            this.boxTypeID = config.boxTypeID;
            this.value = config.value.Clone();
            this.data  = config.data.Clone();            
        }
    }

    namespace Ranges
    {
        #region data

        public interface IItem
        {
            IItem Clone();
            Type GetRangeType();
        }

        [Serializable]
        public class BoxItem : IItem
        {

            public Vector3 offset = Vector3.zero;
            public Vector3 rotation = Vector3.zero;
            public Vector3 size = Vector3.one;

            public IItem Clone()
            {
                return new BoxItem()
                {
                    offset = this.offset,
                    size = this.size,
                    rotation = this.rotation,

                };
            }

            public Type GetRangeType()
            {
                return typeof(BoxItem);
            }
        }

        [Serializable]
        public class SphereItem : IItem
        {

            public Vector3 offset = Vector3.zero;
            public Single radius = 1;


            public IItem Clone()
            {
                return new SphereItem()
                {
                    offset = this.offset,
                    radius = this.radius,

                };
            }

            public Type GetRangeType()
            {
                return typeof(SphereItem);
            }
        }
        [Serializable]
        public class CapsuleItem : IItem
        {
            public Vector3 offset = Vector3.zero;
            public Vector3 rotation = Vector3.zero;
            public Single height = 1f;
            public Single radius = 0.5f;

            public IItem Clone()
            {
                return new CapsuleItem()
                {
                    offset = this.offset,
                    radius = this.radius,
                    rotation = this.rotation,
                    height = this.height,
                };
            }

            public Type GetRangeType()
            {
                return typeof(CapsuleItem);
            }
        }

        [Serializable]
        public class RectItem : IItem
        {

            public Vector2 offset = Vector2.up;
            public Vector2 size = Vector2.one;
            public Vector3 rotation = Vector3.zero;

            public IItem Clone()
            {
                return new RectItem()
                {
                    offset = this.offset,
                    size = this.size,
                    rotation = this.rotation,
                };
            }

            public Type GetRangeType()
            {
                return typeof(RectItem);
            }
        }

        [Serializable]
        public class CircleItem : IItem
        {

            public Vector2 offset = Vector2.zero;
            public Single radius = 1;

            public IItem Clone()
            {
                return new CircleItem()
                {
                    offset = this.offset,
                    radius = this.radius,

                };
            }

            public Type GetRangeType()
            {
                return typeof(CircleItem);
            }
        }

        public class RangeTypesAttribute : ObjectTypesAttribute
        {
            public override Type baseType => typeof(IItem);
        }

        #endregion data
    }
    namespace BoxData
    {
        public interface IBoxData
        {
            IBoxData Clone();
            Type GetDataType();
        }
        public class BoxDataTypesAttribute : ObjectTypesAttribute
        {
            public override Type baseType => typeof(IBoxData);
        }
    }
    
}